<?php
/**
 * Ora 模块类
 * @author lan7
 * @copyright lan7.net
 */
if(!defined('IN_ORA')) {
	exit('Access Denied');
}

class mod{
	var $db = null;
	private  $tpl = null;
	var $mod = null;
	var $act = null;
	var $msgtpl = null;
	var $isAjax = false;
	function __construct(){
		$this->tpl = &$GLOBALS['tpl'];
		$this->db  = &$GLOBALS['db'];
		$this->mod = $GLOBALS['mod'];
		$this->act = $GLOBALS['act'] ==""?"index":$GLOBALS['act'];
		$this->tpl->assign('mod',$GLOBALS['mod']);
		$this->tpl->assign('act',$this->act);
	}

	/**
	 * 设置当前模板文件目录
	 *
	 * @param unknown_type $dir
	 */
	function setTplDir($dir){
		$this->tpl->tpldir = $dir;
	}

	/**
	 * 设置输出消息页面模板
	 *
	 * @param unknown_type $msgtpl
	 */
	function setMsgTpl($msgtpl){
		$this->msgtpl = $msgtpl;
	}

	/**
	 * 设置当前操作是否是Ajax方式
	 *
	 * @param unknown_type $isAjax
	 */
	function setIsAjax($isAjax){
		$this->isAjax = $isAjax;
	}

	/**
	 * 设置引用模板目录
	 *
	 * @param unknown_type $path
	 */
	function setIncludePath($path){
		$this->tpl->includePath = $path;
	}
	
	/**
	 * 检查缓存是否可用
	 *
	 * @param unknown_type $cache_id
	 * @return unknown
	 */
	function isCached($cache_id){
		$this->tpl->cache = true;
		return $this->tpl->isCached($cache_id);
	}

	/**
	 * 输出模板
	 *
	 * @param unknown_type $tplfile
	 * @param unknown_type $ctype
	 */
	function display($tplfile,$ctype=false){
		if($ctype){
			//可输出xml
			$this->tpl->ctype = $ctype;
		}
		$this->tpl->display($tplfile);
	}

	/**
	 * 模板赋值
	 *
	 * @param unknown_type $k
	 * @param unknown_type $v
	 */
	function assign($k,$v){
		$this->tpl->assign($k,$v);
	}
	/**
	 * 输出消息
	 *
	 * @param unknown_type $msg
	 * @param unknown_type $url
	 * @param unknown_type $autoJump
	 */
	function showMsg($msg,$url=null,$autoJump=false){
		if($this->isAjax){
			if(!is_array($msg)){
				exit($msg);
			}else{
				$msg = implode(",",$msg);
				exit($msg);
			}
		}
		$url = empty($url)?HTTP_HOST:$url;
		$this->tpl->assign("msg",$msg);
		$this->tpl->assign("autoJump",$autoJump);
		$this->tpl->assign("url",$url);
		if(!empty($this->msgtpl)){
			/** 使用指定的消息模板 **/
			$this->tpl->display($this->msgtpl);
		}else{
			/** 使用默认消息模板 **/
			$this->tpl->display("msg.html");
		}
		exit();
	}
}

?>